package sz.szsmk.citizencard.ui.activity;

import android.text.TextUtils;
import android.view.View;
import android.widget.Toast;

import com.chenenyu.router.annotation.Route;

import sz.szsmk.citizencard.DaggerApplication;
import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.databinding.SpecialAuthActivityBinding;
import sz.szsmk.citizencard.ioc.Compontent.DaggerCommonActivityComponent;
import sz.szsmk.citizencard.model.network.bean.response.BaseBean;
import sz.szsmk.citizencard.mvp.contract.ISpecialAuthContact;
import sz.szsmk.citizencard.mvp.presenter.SpecialAuthPresenter;
import sz.szsmk.citizencard.ui.base.IBaseActivity;
import sz.szsmk.citizencard.util.TimeCount;

/**
 * Copyright (c)2019
 * author: zdh
 * created on: 2019/1/8 21:46
 * description:
 */
@Route("SpecialAuthActivity")
public class SpecialAuthActivity extends IBaseActivity<SpecialAuthPresenter, SpecialAuthActivityBinding>
        implements ISpecialAuthContact.ISpecialAuthView, View.OnClickListener {

    private String cardNo;
    private String name;
    private String idNo;
    private String phone;

    @Override
    protected int attachLayoutRes() {
        return R.layout.special_auth_activity;
    }

    @Override
    protected void initInjector() {
        DaggerCommonActivityComponent.builder().appCompontent(DaggerApplication.getAppComponent())
                .build().inject(this);
    }

    @Override
    protected void initViews() {
        dataBinding.titleLayout.settingTitle.setText("专有账户认证");
        dataBinding.titleLayout.back.setOnClickListener(this);
        dataBinding.btnCommit.setOnClickListener(this);
        dataBinding.specialGetcodeBtn.setOnClickListener(this);
        cardNo = getIntent().getStringExtra("cardNo");
    }

    @Override
    protected void updateViews() {

    }

    @Override
    public void getSmsFail() {

    }

    @Override
    public void getSmsSucc() {

    }

    @Override
    public void toAuthFail(BaseBean response) {
        Toast.makeText(this, response.getMessage(), Toast.LENGTH_SHORT).show();
    }

    @Override
    public void toAuthSucc(BaseBean response) {
        Toast.makeText(this, response.getMessage(), Toast.LENGTH_SHORT).show();
        finish();
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.back) {
            finish();
        } else if (id == R.id.special_getcode_btn) {
            name = dataBinding.specialEt1.getText().toString().trim();
            idNo = dataBinding.specialEt2.getText().toString().trim();
            phone = dataBinding.specialEt3.getText().toString().trim();
            if (TextUtils.isEmpty(name)) {
                Toast.makeText(this, "请输入姓名", Toast.LENGTH_SHORT).show();
                return;
            }
            if (TextUtils.isEmpty(idNo)) {
                Toast.makeText(this, "请输入身份证号", Toast.LENGTH_SHORT).show();
                return;
            }
            if (TextUtils.isEmpty(phone)) {
                Toast.makeText(this, "请输入手机号", Toast.LENGTH_SHORT).show();
                return;
            }
            setTimeCount();
            mPresenter.getSms(phone);
        } else if (id == R.id.btn_commit) {
            String checkCode = dataBinding.specialEt4.getText().toString().trim();
            if (TextUtils.isEmpty(checkCode)) {
                Toast.makeText(this, "请输入验证码", Toast.LENGTH_SHORT).show();
                return;
            }
            mPresenter.toAuth(cardNo, checkCode, idNo, phone, name);
        }
    }
    private TimeCount timeCount;
    private void setTimeCount() {
        timeCount = new TimeCount(dataBinding.specialGetcodeBtn, 60000, 1000);
        timeCount.start();
//        dataBinding.checkBtnAgain.setOnClickListener(this);
    }
}
